﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace BF
{
	public class BF_UnitType
	{
		public String Name;
		public double FuelCons, FuelCap;

		public BF_UnitType(string iname, double ifuelcap, double ifuelcons)
		{
			Name = iname;
			FuelCap = ifuelcap;
			FuelCons = ifuelcons;
		}
	}
	public class BF_Unit : Obj3G
	{
		BF_UnitType Type;
		public double Fuel;

		public BF_Unit(BF_UnitType type, double longit, double latit, double elev, double hdg)
			: base(longit, latit, elev, hdg)
		{
			Type = type;
		}

		public override void Process(double dt)
		{
			base.Process(dt);
			Fuel -= dt * Type.FuelCons * Speed;
		}

		public void Stop()
		{
			Speed = 0;
		}
		public void Move(double ispeed)
		{
			Speed = ispeed;
		}
	}
	public class BF_WeaponBase
	{
		public String Name;
		public double MinRange, MaxRange;
		public double MinDamage, MaxDamage;
		public double ReloadTime = 10;
		public BF_WeaponBase(String n)
		{
			Name = n;
		}
		public void SetDamage(double rng1, double rng2, double dmg1, double dmg2)
		{
			MinRange = rng1;
			MinRange = rng2;
			MinDamage = dmg1;
			MinDamage = dmg2;
		}
		public void SetReload(double t)
		{
			ReloadTime = t;
		}
		public int NumAmmo;
		public V3D[] AmmoOffsets;

		public virtual BF_Bullet[] ShootBullets()
		{
			return null;
		}
	}
	public enum WeaponState
	{
		Reload,
		Firing,
		Aimed
	}
	public delegate void BF_BulletEvent(BF_Bullet bullet);
	public enum BF_BulletState
	{
		Fired,
		Impact
	}
	public class BF_Weapon
	{
		BF_WeaponBase Base;
		public BF_Bullet[] CreateBullet(BF_Unit owner)
		{
			List<BF_Bullet> Res = new List<BF_Bullet>();
			for (int i = 0; i < Base.NumAmmo; i++)
			{
				//BF_Bullet B =Base.CreateBullet(this);
				//B.Owner = owner;
				//Res.Add(B);
			}
			throw new NotImplementedException();
		}
		public bool CanFire;
		WeaponState state = WeaponState.Reload;
		double reloadtimer = 0;
		public void Process(double dt)
		{
			if (state == WeaponState.Reload)
			{
				reloadtimer += dt;
				if (reloadtimer > Base.ReloadTime)
				{
					state = WeaponState.Aimed;
					reloadtimer = 0;
					CanFire = true;
				}
			}
			else if (state == WeaponState.Firing)
			{
				CanFire = false;
			}
		}
	}
	public class BF_Building
	{
	}

	public enum BF_TileType
	{
		Water1,
		Water2,
		Water3,
		Coast_Sand,
		Coast_Rock,
		Meadow,
		Forest,
		Rock,
		Mountain
	}
}